﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using Microsoft.Practices.Prism.Regions;
using Castle.Windsor;
using Castle.MicroKernel.Registration;
using Tanmia.Basis.ViewInterface;
using Tanmia.Basis.ServiceInterface;
using System.Windows.Controls.Primitives;

namespace SaryaAccounting
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    /// <remarks>
    /// The Export attribute does not use a name like the other views need.  <see cref="ItemView"/>.
    /// The reason for this is because this view is never naviagted to, instead it is created in the
    /// application <see cref="Bootstrapper"/>.
    /// </remarks>
    public partial class MainWindow : Window, IShellView
    {
        #region Private Fields
        private double height;
        private double width;
        private double top;
        private double left;
        #endregion

        public MainWindow(MainViewModel viewModel)
        {
            InitializeComponent();
            this.DataContext = viewModel;
        }

        #region Event Handler

        private void MaxAndNormalButton_Toggeled(object sender, RoutedEventArgs e)
        {
            if ((bool)((ToggleButton)e.OriginalSource).IsChecked)
            {
                WindowState = WindowState.Maximized;
            }
            else
            {
                this.Height = height;
                this.Width = width;
                this.Top = top;
                this.Left = left;

                WindowState = WindowState.Normal;
            }
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            height = this.ActualHeight;
            width = this.ActualWidth;
            top = this.Top;
            left = this.Left;
        }

        private void TitleBar_MouseDown(object sender, MouseButtonEventArgs e)
        {
            FrameworkElement fe = e.OriginalSource as FrameworkElement;
            if (fe.Name == "CaptionBorder")
                if (e.ChangedButton == MouseButton.Left)
                    DragMove();
        }

        private void CloseAndMin_Click(object sender, RoutedEventArgs e)
        {
            FrameworkElement fe = e.OriginalSource as FrameworkElement;
            if (fe != null)
                if (fe.Name == "MinButton")
                    WindowState = System.Windows.WindowState.Minimized;
                else if (fe.Name == "CloseButton")
                    Close();
        }
        #endregion

        #region IShellView Members

        public void ShowWaitCursor(bool status)
        {
            Cursor = status ? Cursors.Wait : Cursors.Arrow;
        }

        public void UpdateStatus(string status)
        {
            tbStatus.Text = status;
        }

        #endregion
    }
}
